package com.heima.article.feign;

import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ArticleService;
import com.heima.model.article.dtos.ApArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ArticleService apArticleService;

    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(@RequestBody ApArticleDto dto) {
        Long id = apArticleService.saveArticle(dto);
        return ResponseResult.okResult(200,id+"");
        //return apArticleService.saveArticle(dto);
    }

    @Override
    @PostMapping("/api/v1/article/down")
    public String down(@RequestBody Long articleId) {
        return apArticleService.getUrl(articleId);
    }

    @Override
    @DeleteMapping("/api/v1/article/delete")
    public ResponseResult delete(@RequestBody Long articleId) {
        return apArticleService.delete(articleId);
    }

}